<extend name="./public/frame.html"/>
<block name="content">
    <style>
        .layui-form-label{width: 12%;}
        .layui-input-block{margin-left: 12%;}
    </style>
    <form class="layui-form layui-form-pane1" method="post" enctype="multipart/form-data">
        <table class="layui-table">
            <tr>
                <td colspan="2" style="font-weight: bold;color: black;">营运城市</td>
            </tr>
            <tr>
                <td style="width: 13%;text-align: center;">所属区域</td>
                <td>
                    <div class="layui-input-inline" style="width: 200px;margin-right: 5px;">
                        <select name="province_id" id="province_id" lay-verify="required" lay-filter="province">
                            <option value="">请选择省份</option>
                            <option value="0" <?php if($info['province_id'] == 0):?>selected<?php endif;?>>默认省份</option>
                            <?php foreach($provinceList as $key=>$value):?>
                            <option value="<?php echo $value['region_id'];?>" <?php if($info['province_id'] == $value['region_id']):?>selected<?php endif;?>><?php echo $value['region_name'];?></option>
                            <?php endforeach;?>
                        </select>
                    </div>
                    <div class="layui-input-inline" style="width: 200px;margin-right: 5px;">
                        <select name="city_id" id="city_id" lay-filter="city">
                            <option value="">请选择城市</option>
                            <option value="0" <?php if($info['city_id'] == 0):?>selected<?php endif;?>>默认城市</option>
                            <?php foreach($cityList as $key=>$value):?>
                            <option value="<?php echo $value['region_id'];?>" <?php if($info['city_id'] == $value['region_id']):?>selected<?php endif;?>><?php echo $value['region_name'];?></option>
                            <?php endforeach;?>
                        </select>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="text-align: center;">城市首字母</td>
                <td><input type="text" name="first_name" id="first_name" value="<?php echo $info['first_name'];?>" lay-verify="required" placeholder="请输入城市首字母(必须大写) 例如：H" class="layui-input" style="width: 880px;" onkeyup="zimu(this)"></td>
            </tr>
            <tr>
                <td style="text-align: center;">推送订单最大数目</td>
                <td><input type="text" name="push_order_limit" id="push_order_limit"  placeholder="同一用户坐同一司机一天推送订单最大数目" class="layui-input" style="width: 880px;" value="<?php echo $info['push_order_limit'];?>" ></td>
            </tr>
            <tr>
                <td style="text-align: center;">是否开启 - 异地接单</td>
                <td>
                    <input type="checkbox" data-type="certificate" lay-filter="remote_order" value="<?php echo $info['remote_order'];?>" lay-skin="switch" class="remote_order" lay-text="开启|关闭"  name="remote_order" <?php if($info['remote_order'] == 1):?>checked<?php endif;?>>

                </td>
            </tr>
            <tr>
                <td style="text-align: center;">平台手续费(%)</td>
                <td><input type="text" name="plate_fee" id="plate_fee" value="<?php echo $info['plate_fee'];?>" placeholder="请输入平台手续费(%)" class="layui-input" style="width: 880px;" onkeyup="num(this)"></td>
            </tr>
            <tr>
                <td style="text-align: center;">是否开启 - 取消订单扣费规则</td>
                <td>
                    <input type="checkbox" data-type="certificate" lay-skin="switch" lay-filter="switchCheck" class="check" lay-text="开启|关闭" value="<?php echo $info['is_cancel'];?>" name="is_cancel" <?php if($info['is_cancel'] == 1):?>checked<?php endif;?>>
                </td>
            </tr>

            <tr class="cancelOrder" <?php if($info['is_cancel'] == 0):?>style="display: none;"<?php endif?>>
                <td colspan="2">
                    <table class="layui-table">
                        <tr>
                            <td colspan="6" style="font-weight: bold;color: black;">取消订单扣费规则</td>
                        </tr>
                        <tr>
                            <td style="text-align: center;">有责取消费用（低 - 元）</td>
                            <td style="text-align: center;">有责取消费用（高 - 元）</td>
                            <td style="text-align: center;">司机出发时长（minute）</td>
                            <td style="text-align: center;">司机到达时长（minute）</td>
                            <td style="text-align: center;">预约时间剩余时长（minute）</td>
                            <td style="text-align: center;">无责取消最大次数</td>
                            <td style="text-align: center;">用户有责取消费用(司机接单后取消) </td>
                        </tr>
                        <tr>
                            <td><input type="text" value="<?php echo $info['low_fee']/100;?>" name="low_fee" id="low_fee" placeholder="有责取消费用（低）" class="layui-input" onkeyup="num(this)"></td>
                            <td><input type="text" value="<?php echo $info['high_fee']/100;?>" name="high_fee" id="high_fee" placeholder="有责取消费用（高）" class="layui-input" onkeyup="num(this)"></td>
                            <td><input type="text" value="<?php echo $info['leave_time']/60;?>" name="leave_time" id="leave_time" placeholder="司机出发时长" class="layui-input" onkeyup="num(this)"></td>
                            <td><input type="text" value="<?php echo $info['arrive_time']/60;?>" name="arrive_time" id="arrive_time" placeholder="司机到达时长" class="layui-input" onkeyup="num(this)"></td>
                            <td><input type="text" value="<?php echo $info['book_remain_time']/60;?>" name="book_remain_time" id="book_remain_time" placeholder="预约时间剩余时长" class="layui-input" onkeyup="num(this)"></td>
                            <td><input type="text" value="<?php echo $info['user_cancel_order'];?>" name="user_cancel_order" id="user_cancel_order" placeholder="无责取消最大次数" class="layui-input" onkeyup="num(this)"></td>
                            <td><input type="text" value="<?php echo $info['user_cancel_fee']/100;?>" name="user_cancel_fee" id="user_cancel_fee" placeholder="用户有责取消费用(元)(司机接单后取消)" class="layui-input" onkeyup="num(this)"></td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td style="text-align: center;">是否开启 - 计价规则</td>
                <td>
                    <input type="checkbox" data-type="certificate" lay-skin="switch" lay-filter="switchSuburbCheck" class="valuation" lay-text="开启|关闭" value="<?php echo $info['is_valuation'];?>" name="is_valuation" <?php if($info['is_valuation'] == 1):?>checked<?php endif;?>>
                </td>
            </tr>
            <tr class="suburbPriceTemplet" <?php if($info['is_valuation'] == 0):?>style="display: none;"<?php endif?>>
                <td colspan="2">
                    <table class="layui-table">
                        <tr>
                            <td colspan="8" style="font-weight: bold;color: black;">普通时段计价规则配置</td>
                        </tr>
                        <tr>
                            <td style="text-align: center;">起步里程(KM)</td>
                            <td style="text-align: center;">起步价(元)</td>
                            <td style="text-align: center;">里程费(元/KM)</td>
                            <td style="text-align: center;">起步时长(分)</td>
                            <td style="text-align: center;">时长费(元/分)</td>
                            <td style="text-align: center;">免费等待时长(分)</td>
                            <td style="text-align: center;">超时等待费(元/分)</td>
                            <td style="text-align: center;">超时等待费上限(元)</td>
                        </tr>
                        <tr>
                            <td style="text-align: center;"><input type="text" name="start_mileage" id="start_mileage" placeholder="起步里程" value="<?php echo $info['start_mileage']/1000;?>" class="layui-input" onkeyup="num(this)"></td>
                            <td style="text-align: center;"><input type="text" name="start_fee" id="start_fee" placeholder="起步价(元)" value="<?php echo $info['start_fee']/100;?>" class="layui-input" onkeyup="num(this)"></td>
                            <td style="text-align: center;"><input type="text" name="mileage_fee" id="mileage_fee" placeholder="里程费(元/KM)" value="<?php echo $info['mileage_fee']/100;?>" class="layui-input" onkeyup="num(this)"></td>
                            <td style="text-align: center;"><input type="text" name="start_time" id="start_time" placeholder="起步时长(分)" value="<?php echo $info['start_time']/60;?>" class="layui-input" onkeyup="num(this)"></td>
                            <td style="text-align: center;"><input type="text" name="time_fee" id="time_fee" placeholder="时长费(元/分)" value="<?php echo $info['time_fee']/100;?>" class="layui-input" onkeyup="num(this)"></td>
                            <td style="text-align: center;"><input type="text" name="free_wait_time" id="free_wait_time" placeholder="免费等待时长(分)" value="<?php echo $info['free_wait_time']/60;?>" class="layui-input" onkeyup="num(this)"></td>
                            <td style="text-align: center;"><input type="text" name="over_wait_fee" id="over_wait_fee" placeholder="超时等待费(元/分)" value="<?php echo $info['over_wait_fee']/100;?>" class="layui-input" onkeyup="num(this)"></td>
                            <td style="text-align: center;"><input type="text" name="over_wait_fee_max" id="over_wait_fee_max" placeholder="超时等待费上限(元)" value="<?php echo $info['over_wait_fee_max']/100;?>" class="layui-input" onkeyup="num(this)"></td>
                        </tr>
                        <tr>
                            <td colspan="8" style="font-weight: bold;color: black;">特殊时段计价规则配置</td>
                        </tr>
                        <tr>
                            <td colspan="8">
                                <table class="layui-table ruleTimeFee">
                                    <tr>
                                        <td style="text-align: center;">时段名称</td>
                                        <td style="text-align: center;">起始时间</td>
                                        <td style="text-align: center;">终止时间</td>
                                        <td style="text-align: center;">起步价(元)</td>
                                        <td style="text-align: center;">里程费(元/KM)</td>
                                        <td style="text-align: center;">时长费(元/分)</td>
                                        <td style="text-align: center;">
                                            超时等待费(元/分)
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="look" style="width: 30px" id="addPrices">+</a>
                                        </td>
                                    </tr>
                                    <?php if(!empty($priceList)):?>
                                    <?php foreach($priceList as $key=>$value):?>
                                    <tr>
                                        <td style="text-align: center;"><input type="text" value="<?php echo $value['name'];?>" name="name[]" id="name_<?php echo $key+1;?>" placeholder="时段名称" class="layui-input"></td>
                                        <td style="text-align: center;"><input type="text" value="<?php echo $value['start_time'];?>" name="start_timey[]" id="start_timey_<?php echo $key+1;?>" placeholder="起始时间（时分）" class="layui-input LAY_demorange_s<?php echo $key+1;?>"></td>
                                        <td style="text-align: center;"><input type="text" value="<?php echo $value['end_time'];?>" name="end_time[]" id="end_time_<?php echo $key+1;?>" placeholder="终止时间（时分）" class="layui-input LAY_demorange_e<?php echo $key+1;?>"></td>
                                        <td style="text-align: center;"><input type="text" value="<?php echo $value['start_price']/100;?>" name="start_price[]" id="start_price_<?php echo $key+1;?>" placeholder="起步价(元/KM)" class="layui-input" onkeyup="num(this)"></td>
                                        <td style="text-align: center;"><input type="text" value="<?php echo $value['mileage_fee']/100;?>" name="mileage_feey[]" id="mileage_feey_<?php echo $key+1;?>" placeholder="里程费(元/KM)" class="layui-input" onkeyup="num(this)"></td>
                                        <td style="text-align: center;"><input type="text" value="<?php echo $value['time_fee']/100;?>" name="time_feey[]" id="time_feey_<?php echo $key+1;?>" placeholder="时长费(元/分)" class="layui-input" onkeyup="num(this)"></td>
                                        <td style="text-align: center;">
                                            <input type="text" value="<?php echo $value['over_time_fee']/100;?>" name="over_time_fee[]" id="over_time_fee_<?php echo $key+1;?>" placeholder="超时等待费(元/分)" class="layui-input" style="width: 150px;float: left;" onkeyup="num(this)">
                                            <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="look" style="width: 30px;margin-top: 8px;" onclick="reduceInsidePrice(this)">-</a>
                                        </td>
                                    </tr>
                                    <?php endforeach;?>
                                    <?php else:?>
                                    <tr>
                                        <td style="text-align: center;"><input type="text" name="name[]" id="name_1" placeholder="时段名称" class="layui-input"></td>
                                        <td style="text-align: center;"><input type="text" name="start_timey[]" id="start_timey_1" placeholder="起始时间（时分）" class="layui-input LAY_demorange_s"></td>
                                        <td style="text-align: center;"><input type="text" name="end_time[]" id="end_time_1" placeholder="终止时间（时分）" class="layui-input LAY_demorange_e"></td>
                                        <td style="text-align: center;"><input type="text" name="start_price[]" id="start_price_1" placeholder="起步价(元/KM)" class="layui-input" onkeyup="num(this)"></td>
                                        <td style="text-align: center;"><input type="text" name="mileage_feey[]" id="mileage_feey_1" placeholder="里程费(元/KM)" class="layui-input" onkeyup="num(this)"></td>
                                        <td style="text-align: center;"><input type="text" name="time_feey[]" id="time_feey_1" placeholder="时长费(元/分)" class="layui-input" onkeyup="num(this)"></td>
                                        <td style="text-align: center;">
                                            <input type="text" name="over_time_fee[]" id="over_time_fee_1" placeholder="超时等待费(元/分)" class="layui-input" style="width: 150px;float: left;" onkeyup="num(this)">
                                            <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="look" style="width: 30px;margin-top: 8px;" onclick="reduceInsidePrice(this)">-</a>
                                        </td>
                                    </tr>
                                    <?php endif;?>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="8" style="font-weight: bold;color: black;">远途费规则配置</td>
                        </tr>
                        <tr>
                            <td colspan="8">
                                <table class="layui-table yuantuRuleTimeFee">
                                    <tr>
                                        <td style="text-align: center;width: 20%">起始公里数（KM）</td>
                                        <td style="text-align: center;width: 20%">终止公里数（KM）</td>
                                        <td style="text-align: center;width: 20%">里程费(元/公里)
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="look" style="width: 30px" id="yuantu">+</a>
                                        </td>
                                    </tr>
                                    <?php if(!empty($frPriceList)):?>
                                    <?php foreach($frPriceList as $key=>$value):?>
                                    <tr>
                                        <td style="text-align: center;"><input type="text" value="<?php echo $value['start_mileage']/1000;?>" name="start_mileagey[]" placeholder="起始公里数（KM）" class="layui-input" onkeyup="num(this)"></td>
                                        <td style="text-align: center;"><input type="text" value="<?php echo $value['end_mileage']/1000;?>" name="end_mileagey[]" placeholder="终止公里数（KM）" class="layui-input" onkeyup="num(this)"></td>
                                        <td style="text-align: center;">
                                            <input type="text" value="<?php echo $value['mileage_fee']/100;?>" name="yuantu_mileage_fee[]" placeholder="里程费（元/KM）" class="layui-input" onkeyup="num(this)" style="width:90%;float: left;">
                                            <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="look" style="width: 30px;margin-top: 8px;" onclick="reduceInsidePrice(this)">-</a>
                                        </td>
                                    </tr>
                                    <?php endforeach;?>
                                    <?php else:?>
                                    <tr>
                                        <td style="text-align: center;"><input type="text" name="start_mileagey[]" placeholder="起始公里数（KM）" class="layui-input" onkeyup="num(this)"></td>
                                        <td style="text-align: center;"><input type="text" name="end_mileagey[]" placeholder="终止公里数（KM）" class="layui-input" onkeyup="num(this)"></td>
                                        <td style="text-align: center;">
                                            <input type="text" name="yuantu_mileage_fee[]" placeholder="里程费（元/KM）" class="layui-input" onkeyup="num(this)" style="width:90%;float: left;">
                                            <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="look" style="width: 30px;margin-top: 8px;" onclick="reduceInsidePrice(this)">-</a>
                                        </td>
                                    </tr>
                                    <?php endif;?>
                                </table>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" value="<?php echo $info['id'];?>" id="id" name="id">
                <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <script>
        layui.use(['form','laydate'], function () {
            var form = layui.form,laydate = layui.laydate;
            <?php foreach($priceList as $key=>$value):?>
            laydate.render({
                elem: '.LAY_demorange_s'+<?php echo $key+1;?>,
                type:'time',
                format: 'H:mm'
            });
            laydate.render({
                elem: '.LAY_demorange_e'+<?php echo $key+1;?>,
                type:'time',
                format: 'H:mm'
            });
            <?php endforeach;?>
            form.on('select(province)', function(data){
                var province_id = data.value;
                if(province_id == 0){
                    $("#city_id").empty();
                    $("#city_id").append('<option value=0>默认城市</option>');
                    form.render('select');
                    return false;
                }
                $("#city_id").empty();
                $("#city_id").append('<option value=>请选择城市</option>');
                $.ajax({
                    url:'{:url("/admin/Franchisee/cityList")}',
                    async:true,
                    //dataType:'json',
                    type:'post',
                    data:{'province_id':province_id},
                    success:function(res){
                        $("#city_id").append(res);
                        form.render('select');
                    },
                    error:function(e){
                        layer.msg('请求错误');return false;
                    }
                })
            });
            //取消订单规则设置
            form.on('switch(switchCheck)', function(data){
                if(!this.checked){
                    var value = 0;
                    $('.cancelOrder').css('display','none');
                }else{
                    var value = 1;
                    $('.cancelOrder').css('display','');
                }
                $('.check').val(value);
            });
            //取消订单规则设置
            form.on('switch(remote_order)', function(data){
                if(!this.checked){
                    var value = 0;
                    $('.remote_order').css('display','none');
                }else{
                    var value = 1;
                    $('.remote_order').css('display','');
                }
                $('.remote_order').val(value);
            });
            //计价规则设置
            form.on('switch(switchSuburbCheck)', function(data){
                if(!this.checked){
                    var value = 0;
                    $('.suburbPriceTemplet').css('display','none');
                }else{
                    var value = 1;
                    $('.suburbPriceTemplet').css('display','');
                }
                $('.valuation').val(value);
            });
            //特殊时段累计
            $('#addPrices').click(function(){
                var j  = $('.ruleTimeFee tr').length-1;
                j++;
                var html = '<tr>\n' +
                    '<td style="text-align: center;"><input type="text" name="name[]" id="name_'+j+'" placeholder="时段名称" class="layui-input"></td>\n' +
                    '<td style="text-align: center;"><input type="text" name="start_timey[]" id="start_timey_'+j+'" placeholder="起始时间（时分）" class="layui-input LAY_demorange_s'+j+'"></td>\n' +
                    '<td style="text-align: center;"><input type="text" name="end_time[]" id="end_time_'+j+'" placeholder="终止时间（时分）" class="layui-input LAY_demorange_e'+j+'"></td>\n' +
                    '<td style="text-align: center;"><input type="text" name="start_price[]" id="start_price_'+j+'" placeholder="起步价(元/KM)" class="layui-input" onkeyup="num(this)"></td>\n' +
                    '<td style="text-align: center;"><input type="text" name="mileage_feey[]" id="mileage_feey_'+j+'" placeholder="里程费(元/KM)" class="layui-input" onkeyup="num(this)"></td>\n' +
                    '<td style="text-align: center;"><input type="text" name="time_feey[]" id="time_feey_'+j+'" placeholder="时长费(元/分)" class="layui-input" onkeyup="num(this)"></td>\n' +
                    '<td style="text-align: center;">\n' +
                    '<input type="text" name="over_time_fee[]" id="over_time_fee_'+j+'" placeholder="超时等待费(元/分)" class="layui-input" style="width: 150px;float: left;" onkeyup="num(this)">\n' +
                    '<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="look" style="width: 30px;margin-top: 8px;" onclick="reduceInsidePrice(this)">-</a>\n' +
                    '</td>\n' +
                    '</tr>';
                $(".ruleTimeFee").append(html);
                laydate.render({
                    elem: '.LAY_demorange_s'+j       //指定元素
                    ,type:'time',
                    format: 'H:mm'
                });
                laydate.render({
                    elem: '.LAY_demorange_e'+j       //指定元素
                    ,type:'time',
                    format: 'H:mm'
                });
            });
            $('#yuantu').click(function(){
                var k  = $('.yuantuRuleTimeFee tr').length-1;
                k++;
                var html = '<tr>\n' +
                    '<td style="text-align: center;"><input type="text" name="start_mileagey[]" placeholder="起始公里数（KM）" class="layui-input" onkeyup="num(this)"></td>\n' +
                    '<td style="text-align: center;"><input type="text" name="end_mileagey[]" placeholder="终止公里数（KM）" class="layui-input" onkeyup="num(this)"></td>\n' +
                    '<td style="text-align: center;">\n' +
                    '<input type="text" name="yuantu_mileage_fee[]" placeholder="里程费（元/KM）" class="layui-input" onkeyup="num(this)" style="width:90%;float: left;">\n' +
                    '<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="look" style="width: 30px;margin-top: 8px;" onclick="reduceInsidePrice(this)">-</a>\n' +
                    '</td>\n' +
                    '</tr>';
                $(".yuantuRuleTimeFee").append(html);
            })
        });
        //验证只能输入字母
        function zimu(object) {
            var value = object.value;
            var id      = object.id;
            var re=/^[A-Z]+$/;
            if(value.length > 1){
                layer.msg('请输入一位首字母',{icon: 5});
                $("#"+id).val('');
                return false;
            }
            if(!re.test(value)){
                layer.msg('请输入城市首字母(必须大写)',{icon: 5});
                $("#"+id).val('');
                return false;
            }
        }
        //验证只能输入数字
        function num(object) {
            var value   = object.value;
            var id      = object.id;
            if (isNaN(value)){
                layer.msg('请输入正确的数字',{icon: 5});
                $("#"+id).val('');
                return false;
            }
        }
        //减少特殊时段 + 远途
        function reduceInsidePrice($this) {
            $($this).parent().parent().remove();
        }
    </script>
</block>
